package com.juqimiao.raccoon.commodity.domain.category;

import com.juqimiao.linn.domain.ValueObject;
import com.juqimiao.linn.extension.ExtensionExecutor;
import com.juqimiao.raccoon.commodity.domain.support.extension.CategoryGroupPolicyExtPt;
import lombok.Getter;
import lombok.Setter;
import org.springframework.aop.scope.ScopedProxyFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.function.Function;

/**
 * 固定规则
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CategoryGroupPolicy extends ValueObject {
    private static final long serialVersionUID = 85938272227L;

    @Autowired
    private ExtensionExecutor executor;

    @Getter
    @Setter
    private CategoryGroup categoryGroup;

    public CategoryGroupPolicy() {

    }

    public boolean hasSameName() {
        return executor.execute(CategoryGroupPolicyExtPt.class, ext -> ext.checkSameNamePolicy(categoryGroup));
    }

    public boolean canUpdate() {
        return executor.execute(CategoryGroupPolicyExtPt.class, ext -> ext.canUpdatePolicy(categoryGroup));
    }

    public boolean checkPublish() {
        return !categoryGroup.getPublish();
    }
}
